package api

import (
	"day5/user-sage/api-getaway/basic/config"
	"day5/user-sage/api-getaway/basic/handler/request"
	"day5/user-sage/api-getaway/basic/proto"
	"day5/user-sage/auth-service/basic/pkg"
	"log"
	"net/http"
)

func Login(c *gin.Context) {

	var user request.User
	err := c.ShouldBind(&user)
	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 0,
			"msg":  "参数错误",
		})
		return
	}
	r, err := config.UserClient.CreateUser(c, &__.LoginUserReq{
		Username: user.Username,
		Password: pkg.Md5str(user.Password),
	})
	if err != nil {
		log.Fatalf("could not greet: %v", err)
	}
	c.JSON(http.StatusOK, gin.H{
		"code": r.Code,
		"msg":  r.Msg,
	})

}
